package com.cjy.controller.dept;

import com.cjy.common.utils.PreconditionsUtils;
import com.cjy.entity.dept.DeptEntity;
import com.cjy.service.dept.DeptService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.ApiImplicitParam;
import com.cjy.common.message.BaseResult;
import com.cjy.common.message.AjaxResult;
import com.cjy.common.message.ResultPage;
import com.cjy.vo.dept.DeptVo;
import com.cjy.common.message.IdsParamVo;
import java.util.List;

/**
 * 功能：部门表dept的Api
 *
 * @author Cheng JiYe
 * @version 1.0 @Date 2021年11月13日 03:23:30
 */
@RestController
@Api(tags = "部门表API")
public class DeptController {

  private Logger logger = LoggerFactory.getLogger(getClass());

  @Autowired private DeptService deptService;

  @ApiOperation(value = "获取部门表", notes = "根据主键id，获取部门表详情")
  @PostMapping(value = "/ac/admin/dept/dept/id")
  public AjaxResult<DeptEntity> getByIdDetails(@RequestBody IdsParamVo vo) {
    PreconditionsUtils.checkNotNull(vo.getId(), "id不能为空");
    DeptEntity dbObj = deptService.getByIdDetails(vo.getId());
    return AjaxResult.success("获取成功", dbObj);
  }

  @ApiOperation(value = "查询部门表的列表")
  @PostMapping(value = "/ac/admin/dept/dept/list")
  public ResultPage<List<DeptEntity>> list(@RequestBody DeptVo vo) {
    return BaseResult.packPageResult(deptService.pageList(vo));
  }

  @ApiOperation(value = "保存或更新部门表")
  @PostMapping(value = "/ac/admin/dept/dept/saveOrUpdate")
  public AjaxResult<DeptEntity> saveOrUpdate(@RequestBody DeptEntity pageObj) {
    DeptEntity dbObj = deptService.saveOrUpdateDo(pageObj);
    return AjaxResult.success("保存成功", dbObj);
  }

  @ApiOperation(value = "删除部门表", notes = "根据主键id，删除部门表")
  @PostMapping(value = "/ac/admin/dept/dept/remove")
  public AjaxResult remove(@RequestBody IdsParamVo vo) {
    PreconditionsUtils.checkNotNull(vo.getIds(), "ids不能为空");
    // 逻辑删除
    deptService.deleteLogicBatchById(vo.getIds());
    return AjaxResult.success("删除成功");
  }

  @ApiOperation(value = "获取部门表", notes = "根据主键id，获取部门表")
  @PostMapping(value = "/ac/admin/dept/dept/listByIds")
  public AjaxResult<List<DeptEntity>> listByIds(@RequestBody IdsParamVo vo) {
    PreconditionsUtils.checkNotNull(vo.getIds(), "ids不能为空");
    List<DeptEntity> list = deptService.getListByIds(vo.getIds());
    return AjaxResult.success("获取成功", list);
  }
}
